package collection.ListTest;

/**
 * list翻转，可以用递归与非递归进行区别
 * @author lcx
 */
public class ListReverse {

	public static void singleReverse(Node a,Node b)
	{
		if(a==null||b==null)
			return;
		Node c=b.next;
		b.next=a;
		singleReverse(b,c);
	}

	public static Node getTail(Node a)
	{
		Node res=a;
		while(res.next!=null)
		{
			res=res.next;
		}
		return res;
	}


	public static void main(String[] args) {
		Node root=new Node(1);
		SingleList list=new SingleList(root);
		list.initSample();
		Node tail=getTail(root);
		Node tag=tail;
		singleReverse(root,root.next);
		root.next=null;
		System.out.println(tail.val);
		while(tag.next!=null)
		{
			tag=tag.next;
			System.out.println(tag.val);
		}
	}
}
